package com.baidu.mapsdkexample.myrouteplan;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.RouteLine;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.route.BikingRouteResult;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.IndoorRouteResult;
import com.baidu.mapapi.search.route.MassTransitRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.search.route.TransitRouteLine;
import com.baidu.mapapi.search.route.TransitRoutePlanOption;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRouteResult;
import com.baidu.mapsdkexample.R;
import com.baidu.mapsdkexample.routeplan.NodeAdapter;
import com.baidu.mapsdkexample.util.overlayutil.TransitRouteOverlay;

import java.util.ArrayList;
import java.util.List;

import cn.leancloud.AVLogger;
import cn.leancloud.AVOSCloud;
import cn.leancloud.AVObject;
import cn.leancloud.AVQuery;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class PlanShowActivity extends AppCompatActivity implements OnGetRoutePlanResultListener {

    private ListView day_plan_list;//定制计划表
    private int maxsize = 160;
    private int[][] timebox = new int[maxsize][maxsize];//时间矩阵
    private double[] forwordprice = new double[maxsize];
    private List<AVObject> pointInfoList;//景点基本信息表
    private List<AVObject> listTimebox;//时间矩阵-数据库
    private boolean[] mark = new boolean[maxsize];//单天内的地点到达标记
    private boolean[] daymark = new boolean[maxsize];//跨天的地点到达标记

    private ArrayList<String> resultplan[] =new ArrayList[10];//存储每天计划

    private ArrayList<String> plannodes1 = new ArrayList<>();
    private ArrayList<String> plannodes2 = new ArrayList<>();
    private ArrayList<String> plannodes3 = new ArrayList<>();
    private ArrayList<String> plannodes4 = new ArrayList<>();
    private int dayplanpage = 1;
    private int daynum =1;

    private int maxdaynum=1;

    private Button bt_before_plan;
    private Button bt_next_plan;
    private Button bt_nextday;

    private List<? extends RouteLine> mRouteLines;
    private MapView mMapView = null;    // 地图View
    private BaiduMap mBaidumap = null;
    private RoutePlanSearch mSearch = null;
    private RouteLine mRouteLine = null;

    ArrayList mytag;
    private double lat;
    private double lng;
    private String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_plan_show);

        //获取起景点种类
        mytag = getIntent().getStringArrayListExtra("mytag");

        //获取起点信息
        lat=getIntent().getDoubleExtra("lat",0);
        lng=getIntent().getDoubleExtra("lng",0);
        name= getIntent().getStringExtra("name");
        maxdaynum=getIntent().getIntExtra("days",0);

        day_plan_list = findViewById(R.id.day_plan_list);
        bt_before_plan = findViewById(R.id.bt_before_plan);
        bt_next_plan = findViewById(R.id.bt_next_plan);
        bt_nextday = findViewById(R.id.bt_nextday);

        mMapView = (MapView) findViewById(R.id.map);
        mBaidumap = mMapView.getMap();
        // 初始化搜索模块，注册事件监听
        mSearch = RoutePlanSearch.newInstance();
        mSearch.setOnGetRoutePlanResultListener(this);

        bt_next_plan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dayplanpage <= 3)
                    dayplanpage++;
                if (getcurrentList(dayplanpage).size() == 0) {
                    core(name, 750,lat,lng);
                    ArrayAdapter<String> nodeAdapter = new NodeAdapter(PlanShowActivity.this, R.layout.layout_plannode_item, getcurrentList(dayplanpage));//刷新listview，可改进？？？？？？
                    day_plan_list.setAdapter(nodeAdapter);
                } else {
                    ArrayAdapter<String> nodeAdapter = new NodeAdapter(PlanShowActivity.this, R.layout.layout_plannode_item, getcurrentList(dayplanpage));//刷新listview，可改进？？？？？？
                    day_plan_list.setAdapter(nodeAdapter);
                }
                searchandshow();
            }
        });
        bt_before_plan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dayplanpage >= 2)
                    dayplanpage--;
                if (getcurrentList(dayplanpage).size() == 0) {
                    core(name, 750,lat,lng);
                    ArrayAdapter<String> nodeAdapter = new NodeAdapter(PlanShowActivity.this, R.layout.layout_plannode_item, getcurrentList(dayplanpage));
                    day_plan_list.setAdapter(nodeAdapter);
                } else {
                    ArrayAdapter<String> nodeAdapter = new NodeAdapter(PlanShowActivity.this, R.layout.layout_plannode_item, getcurrentList(dayplanpage));
                    day_plan_list.setAdapter(nodeAdapter);
                }
                searchandshow();
            }
        });

        if (daynum == maxdaynum){
            bt_nextday.setText("完成");
        }

        bt_nextday.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                resultplan[daynum-1]=new ArrayList<>();     //初始化
                resultplan[daynum-1].addAll( getcurrentList(dayplanpage));//将每天规划结果保存

                if (bt_nextday.getText().equals("完成")){
                    Intent intent=new Intent(PlanShowActivity.this,ResultShowActivity.class);
                    intent.putExtra("days",maxdaynum);
                    for (int i=0;i<maxdaynum;i++) {
                        intent.putStringArrayListExtra("plannodes" + i, resultplan[i]);
                    }
                    startActivity(intent);
                    return;
                }

                daynum++;//天数增加
                if (daynum == maxdaynum){//当到达最大天数时改变按钮文本
                    bt_nextday.setText("完成");
                }

                for (int i=0;i<maxsize;i++) //若选择看过的列表不再看，则该部分可删除
                    mark[i]=false;

                for (int i = 0; i < getcurrentList(dayplanpage).size(); i++) {
                    Log.d("temp","getcurrentList(dayplanpage).get(i) "+getcurrentList(dayplanpage).get(i));
                    if (getcurrentList(dayplanpage).get(i).equals("午餐"))
                        continue;
                    else{
                        int id_inDB=getIdByName_inDB((String) getcurrentList(dayplanpage).get(i));
                        daymark[id_inDB]=true;
                    }
                }

                dayplanpage=1;
                plannodes1.clear();
                plannodes2.clear();
                plannodes3.clear();
                plannodes4.clear();
                core(name, 750,lat,lng);
                ArrayAdapter<String> nodeAdapter = new NodeAdapter(PlanShowActivity.this, R.layout.layout_plannode_item, getcurrentList(dayplanpage));
                day_plan_list.setAdapter(nodeAdapter);
                searchandshow();
            }
        });

        //timebox mark daymark 初始化
        for (int i = 0; i < maxsize; i++) {
            for (int j = 0; j < maxsize; j++)
                timebox[i][j] = -1;
            mark[i] = false;
            daymark[i]=false;
        }

        //leancloud初始化
        AVOSCloud.setLogLevel(AVLogger.Level.DEBUG);
        AVOSCloud.initialize(
                this,
                "gYKKKJUqrlSsLCUDRD1aNRHj-gzGzoHsz",
                "viezs5eeEG4dLaPay20EaEXd",
                "dwxr3lun.api.lncld.net");

        //从数据库获得数据
        AVQuery<AVObject> query = new AVQuery<>("ViewpointInfo");

        String refo= new String();
        Log.d("mytest", String.valueOf(mytag.size()));
        for(int i=0;i<mytag.size();i++){         //生成正则表达式语句
            if (i==mytag.size()-1)
                refo+=".*"+mytag.get(i)+".*";
            else
                refo+=".*"+mytag.get(i)+".*|";
        }
        Log.d("mytest", refo);
        query.whereMatches("tag",refo);
        query.limit(150);
        query.orderByAscending("id");//按照id排序，id的数字对应于ViewpointInfo中的景点名称
        query.findInBackground().subscribe(new Observer<List<AVObject>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<AVObject> avObjects) {
                Log.d("mytest", String.valueOf(avObjects.size()));
                pointInfoList = avObjects;
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });

        //从数据库获得数据
        AVQuery<AVObject> querytimebox = new AVQuery<>("timebox");
        querytimebox.limit(150);
        querytimebox.orderByAscending("id");//按照id排序，id的数字对应于ViewpointInfo中的景点名称
        querytimebox.findInBackground().subscribe(new Observer<List<AVObject>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<AVObject> avObjects) {
                System.out.println("-----------------------------timebox----" + avObjects.size());
                listTimebox = avObjects;
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {
                timboxinit();
                core(name, 750,lat,lng);
                ArrayAdapter<String> nodeAdapter = new NodeAdapter(PlanShowActivity.this, R.layout.layout_plannode_item, getcurrentList(dayplanpage));//刷新listview，可改进？？？？？？
                day_plan_list.setAdapter(nodeAdapter);
                searchandshow();
            }
        });
    }

    //从数据库读入时间表信息
    public void timboxinitx() {
        Log.d("inittimebox","size = "+pointInfoList.size());
        for (int i = 1; i < pointInfoList.size(); i++) {
            Log.d("inittimebox", "" + pointInfoList.get(i).getInt("id"));
        }
        for (int i = 1; i < pointInfoList.size(); i++) {
            if (pointInfoList.get(i).getDouble("overall_rating") == 0)
                Log.d("inittimebox", "overall_rating " + i);

            for (int j=1;j< pointInfoList.size();j++) {
                if (listTimebox.get(i).getInt(String.valueOf(getIdByi_inDB(j))) ==-1 )
                    continue;
                if (j != i){
                    Log.d("inittimebox","x= " +getIdByi_inDB(i)+"  y="+getIdByi_inDB(j)+"  timebox[x][y] ="+listTimebox.get(i).getInt(String.valueOf(getIdByi_inDB(j))));
                    timebox[getIdByi_inDB(i)][getIdByi_inDB(j)] = listTimebox.get(i).getInt(String.valueOf(getIdByi_inDB(j)));
                }
            }
            Log.d("inittimebox",getIdByi_inDB(i)+" is over");
        }

        //显示timebox
        for (int i=1;i<maxsize;i++){
            for (int j=0;j<maxsize;j++){
                System.out.print(timebox[i][j]+" ");
            }
            System.out.println(" ");
        }
    }

    public void timboxinit() {

        for (int i = 0; i < listTimebox.size(); i++) {
            int id_from=listTimebox.get(i).getInt("id");
            Log.d("inittimebox","id_from = "+id_from);
            for (int j=0;j<listTimebox.size();j++){
                int time=listTimebox.get(i).getInt(String.valueOf(j));
                int id_to=listTimebox.get(j).getInt("id");
                if (id_from==0||id_to==0)
                    continue;

                if (time ==-1 || time==-2 )
                    continue;


                timebox[id_from][id_to] = time;
                timebox[id_to][id_from] = time;
            }
        }

        //显示timebox
        for (int i=1;i<maxsize;i++){
            for (int j=1;j<maxsize;j++){
                System.out.print(timebox[i][j]+" ");
            }
            System.out.println(" ");
        }
    }


    public void percore(double startlat,double startlng){

        Log.d("test830","未在景点列表中匹配到结果");
        double mindistance=100;
        int mark=0;
        for (int i = 0; i < pointInfoList.size(); i++) {
            double xlat=pointInfoList.get(i).getDouble("lat");
            double xlng=pointInfoList.get(i).getDouble("lng");
            double distance=(xlat-startlat)*(xlat-startlat)+(xlng-startlng)*(xlng-startlng);
            if (distance<mindistance) {
                mindistance=distance;
                mark=i;
            }
        }
        //查找从lat，lng到i的时间


//        PlanNode plannodestart=PlanNode.withLocation(new LatLng(lat,lng));
//        PlanNode plannodend=PlanNode.withLocation(new LatLng(pointInfoList.get(mark).getDouble("lat"),pointInfoList.get(mark).getDouble("lng")));
//        TransitRoutePlanOption transitRoutePlanOption=new TransitRoutePlanOption().from(plannodestart).to(plannodend).city("北京");
//        mSearch.transitSearch(transitRoutePlanOption);
    }


    //timebox[][]  pointInfoList  mark[]  forwordprice[][]
    //从8.30--9.00 共 750 min
    public void core(String startend, int duration,double startlat,double startlng) {   //当startend字符串无效时，采用经纬度选取地点
        int wholetime = 0;
        int x = 150;
        String midpoint = startend;
        while (true) {
            int se = 0;
            int se_inDB=0;
            for (int i = 0; i < pointInfoList.size(); i++) {
                if (pointInfoList.get(i).getString("name").equals(midpoint)) {
                    se_inDB = pointInfoList.get(i).getInt("id");
                    se=i;
                    break;
                }
            }

            //未在景点列表中匹配到结果
            if (se==0){
                Log.d("test830","未在景点列表中匹配到结果");
                double mindistance=100;
                int mark=0;
                for (int i = 0; i < pointInfoList.size(); i++) {
                    double xlat=pointInfoList.get(i).getDouble("lat");
                    double xlng=pointInfoList.get(i).getDouble("lng");
                    double distance=(xlat-startlat)*(xlat-startlat)+(xlng-startlng)*(xlng-startlng);
                    if (distance<mindistance) {
                        mindistance=distance;
                        mark=i;
                    }
                }
                //查找从lat，lng到i的时间

                Log.d("test830","最小距离 = "+mindistance);

                //-----------------------

                se=mark;
                se_inDB = pointInfoList.get(mark).getInt("id");
            }

            Log.d("test830","se= "+se+" se_inDB= "+se_inDB);
            for (int i = 0; i < pointInfoList.size(); i++) {
                Log.d("show_mark[]",mark[getIdByi_inDB(i)]+"   mark["+getIdByi_inDB(i)+"]");
                if (timebox[se_inDB][getIdByi_inDB(i)] == -1 || timebox[se_inDB][getIdByi_inDB(i)] == -2 || mark[getIdByi_inDB(i)] == true||daymark[getIdByi_inDB(i)]==true)
                    forwordprice[getIdByi_inDB(i)] = 0;
                else {
                    if (getIdByi_inDB(i)==102)
                    {
                        Log.d("special",se_inDB+"  "+getIdByi_inDB(i));
                        Log.d("special",pointInfoList.get(i).getDouble("overall_rating")+" "+timebox[se_inDB][getIdByi_inDB(i)]);
                    }
                    Log.d("mycore","-----");
                    forwordprice[getIdByi_inDB(i)] = pointInfoList.get(i).getDouble("overall_rating") / (timebox[se_inDB][getIdByi_inDB(i)] / 60) * 100;
                }
            }
            Log.d("show_mark[]","-----");
            Log.d("mycore", "se= " + se+"   se_inDB= "+se_inDB);
            double max = 0;
            int maxi_inlist = 1;
            int maxi_inDB=1;
            for (int i = 1; i < pointInfoList.size(); i++) {
                Log.d("mycore", " forwordprice " + getIdByi_inDB(i) + " = " + forwordprice[getIdByi_inDB(i)]);
                if (forwordprice[getIdByi_inDB(i)] > max && getIdByi_inDB(i) != 17) {//---------------------------------------------------------------------------
                    max = forwordprice[getIdByi_inDB(i)];
                    maxi_inlist = i;
                    maxi_inDB=getIdByi_inDB(i);
                }
            }
            Log.d("mycore", "maxi_inDB="+maxi_inDB+ " max= " + max);

            if (wholetime + x + timebox[se_inDB][maxi_inDB] / 60 >= duration) {
                Log.d("testcore","去 "+maxi_inDB+" 超时");
                break;
            } else if (wholetime + x + timebox[se_inDB][maxi_inDB] / 60 >= 150 && wholetime + x + timebox[se_inDB][maxi_inDB] / 60 <= 270) {
                Log.d("testcore","去 "+maxi_inDB+" 后添加午餐时段");
                getcurrentList(dayplanpage).add(pointInfoList.get(maxi_inlist).getString("name"));
                mark[se_inDB] = true;
                midpoint = pointInfoList.get(maxi_inlist).getString("name");
                getcurrentList(dayplanpage).add("午餐");
                wholetime = wholetime + x + timebox[se_inDB][maxi_inDB] / 60 + 120;
            } else {
                Log.d("testcore","去 "+maxi_inDB+" 正常");
                getcurrentList(dayplanpage).add(pointInfoList.get(maxi_inlist).getString("name"));
                mark[se_inDB] = true;
                midpoint = pointInfoList.get(maxi_inlist).getString("name");
                wholetime = wholetime + x + timebox[se_inDB][maxi_inDB] / 60;
            }
            mark[maxi_inDB]=true;
            Log.d("testcore", "交通时间：" +se_inDB+" to "+maxi_inDB+" time= "+ timebox[se_inDB][maxi_inDB] + " midpoint= " + midpoint);
        }
        Log.d("testcore",  " wholetime= " + wholetime);
        Log.d("test830"," core over");
    }

    public List getcurrentList(int position) {
        if (position == 1)
            return plannodes1;
        if (position == 2)
            return plannodes2;
        if (position == 3)
            return plannodes3;
        if (position == 4)
            return plannodes4;
        return null;
    }

    public int getIdByName_inDB(String name) {
        for (int i = 0; i < pointInfoList.size(); i++) {
            if (pointInfoList.get(i).getString("name").equals(name)) {
                return pointInfoList.get(i).getInt("id");
            }
        }
        return 0;
    }

    public int getIdByName_inlist(String name) {
        for (int i = 0; i < pointInfoList.size(); i++) {
            if (pointInfoList.get(i).getString("name").equals(name)) {
                return i;
            }
        }
        return 0;
    }

    public int getIdByi_inDB(int i)
    {
        if (i<=0||i>=pointInfoList.size())
            return 0;
        return pointInfoList.get(i).getInt("id");
    }

    public void searchandshow() {
        if (mRouteLines != null) {
            // 重置路线数据
            mRouteLines.clear();
            mRouteLines = null;
        }

        // 清除之前的覆盖物
        mBaidumap.clear();
        // 设置起终点信息 起点参数
        ArrayList<PlanNode> planNodes=new ArrayList<PlanNode>();
        ArrayList<TransitRoutePlanOption> transitRoutePlanOptions=new ArrayList<TransitRoutePlanOption>();

        //显示所有 列表中的 点
        for (int i=0;i<pointInfoList.size();i++){
            int id_intimebox = getIdByi_inDB(i);
            int id_inlist=i;
            planNodes.add(PlanNode.withLocation(new LatLng(pointInfoList.get(id_inlist).getDouble("lat"), pointInfoList.get(id_inlist).getDouble("lng"))));

            showPoiMarker_blue(pointInfoList.get(id_inlist).getDouble("lat"), pointInfoList.get(id_inlist).getDouble("lng"));
        }

        for (int i=0;i<getcurrentList(dayplanpage).size();i++){
            if (getcurrentList(dayplanpage).get(i).equals("午餐")) {
                continue;
            }
            int id_intimebox = getIdByName_inDB((String) getcurrentList(dayplanpage).get(i));
            int id_inlist=getIdByName_inlist((String) getcurrentList(dayplanpage).get(i));
            Log.d("ididid",id_intimebox+"-----------------------------");
            planNodes.add(PlanNode.withLocation(new LatLng(pointInfoList.get(id_inlist).getDouble("lat"), pointInfoList.get(id_inlist).getDouble("lng"))));

            showPoiMarker(pointInfoList.get(id_inlist).getDouble("lat"), pointInfoList.get(id_inlist).getDouble("lng"));
            Log.d("temp", getcurrentList(dayplanpage).get(i) + "");
        }

        for (int i=0;i<getcurrentList(dayplanpage).size()-2;i++){
            transitRoutePlanOptions.add(new TransitRoutePlanOption().from(planNodes.get(i)).to(planNodes.get(i+1)).city("北京"));
            //
            //
            //发起换乘路线规划
            //mSearch.transitSearch(transitRoutePlanOptions.get(i));//查找-----------------------------------------------------------------
        }
    }

    @Override
    public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {

    }

    @Override
    public void onGetTransitRouteResult(TransitRouteResult result) {
        if (result != null && result.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
            // 起终点或途经点地址有岐义，通过以下接口获取建议查询信息
            // result.getSuggestAddrInfo()
            Toast.makeText(PlanShowActivity.this,
                    "起终点或途经点地址有岐义，通过result.getSuggestAddrInfo()接口获取建议查询信息",
                    Toast.LENGTH_SHORT).show();
            return;
        }

        if (result == null || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
            Toast.makeText(PlanShowActivity.this, "抱歉，未找到结果", Toast.LENGTH_SHORT).show();
            return;
        }

        if (result.error == SearchResult.ERRORNO.NO_ERROR) {
            if (mRouteLines != null) {
                mRouteLines.clear();
            }
            mRouteLines = result.getRouteLines();//返回一个列表
            //
            //
            //
            //自己添加  mRouteLineListAdapter.getCount()
            //暂时取第一个搜索结果
            for (int position=0;position<1;position++) {
                if (mRouteLines == null) {
                    return;
                }

                mRouteLine = mRouteLines.get(position);


                // 路线绘制
                TransitRouteOverlay overlay = new PlanShowActivity.MyTransitRouteOverlay(mBaidumap);
                mBaidumap.setOnMarkerClickListener(overlay);
                overlay.setData((TransitRouteLine) mRouteLine);
                overlay.addToMap();
                overlay.zoomToSpanPaddingBounds(100, 500, 100, 500);
            }
        }
    }

    private static class MyTransitRouteOverlay extends TransitRouteOverlay {


        private MyTransitRouteOverlay(BaiduMap baiduMap) {
            super(baiduMap);
        }

        @Override
        public BitmapDescriptor getStartMarker() {
            return BitmapDescriptorFactory.fromResource(R.drawable.icon_start);
        }

        @Override
        public BitmapDescriptor getTerminalMarker() {
            return BitmapDescriptorFactory.fromResource(R.drawable.icon_end);
        }
    }

    @Override
    public void onGetMassTransitRouteResult(MassTransitRouteResult massTransitRouteResult) {

    }

    @Override
    public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {

    }

    @Override
    public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {

    }

    @Override
    public void onGetBikingRouteResult(BikingRouteResult bikingRouteResult) {

    }


    private Marker mPoiMarker = null;
    private BitmapDescriptor mBitmapDescriptor =
            BitmapDescriptorFactory.fromResource(R.drawable.water_drop);
    private BitmapDescriptor mBitmapDescriptor_blue =
            BitmapDescriptorFactory.fromResource(R.drawable.map);
    /**
     * 显示定位点
     *
     *
     */
    private void showPoiMarker(double lat,double lng) {
        Marker mPoiMarker=null;
        LatLng latLng=new LatLng(lat,lng);
        // 将地图平移到 latLng 位置
        MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLng(latLng);
        mBaidumap.setMapStatus(mapStatusUpdate);

        if (null == latLng) {
            return;
        }

        if (null == mPoiMarker) {
            MarkerOptions markerOptions = new MarkerOptions()
                    .position(latLng)
                    .icon(mBitmapDescriptor)
                    .scaleX(1.5f)
                    .scaleY(1.5f);
            mPoiMarker = (Marker) mBaidumap.addOverlay(markerOptions);
        } else {
            mPoiMarker.setPosition(latLng);
        }
    }

    private void showPoiMarker_blue(double lat,double lng) {
        Marker mPoiMarker=null;
        LatLng latLng=new LatLng(lat,lng);
        // 将地图平移到 latLng 位置
        MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLng(latLng);
        mBaidumap.setMapStatus(mapStatusUpdate);

        if (null == latLng) {
            return;
        }

        if (null == mPoiMarker) {
            MarkerOptions markerOptions = new MarkerOptions()
                    .position(latLng)
                    .icon(mBitmapDescriptor_blue)
                    .scaleX(1.5f)
                    .scaleY(1.5f);
            mPoiMarker = (Marker) mBaidumap.addOverlay(markerOptions);
        } else {
            mPoiMarker.setPosition(latLng);
        }
    }
}